<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title></title>
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
	<style>
		.aui-list-item {
			line-height: 3.5rem;
		}
	</style>
</head>

<body>
	<div style="position: fixed;top: 0;width: 100%;height:45px;z-index: 100;" id="ast">
		<div class="aui-searchbar" id="search" class="aui-content">
			<div class="aui-searchbar-input aui-border-radius" tapmode>
				<i class="aui-iconfont aui-icon-search"></i>
				<form action="javascript:doSearch();">
					<input type="search" placeholder="请输入老人姓名" id="search-input">
				</form>
			</div>
			<div class="aui-searchbar-btn" tapmode>
				取消
			</div>
		</div>
	</div>
	<section class="aui-refresh-content" id="pContainer1">
		<div class="aui-content">
			<ul class="aui-list aui-list-in" tapmode id="list">
			</ul>
		</div>
	</section>
</body>
<script id="listTemplate" type="text/x-dot-template">
	{{for(var i=0;i<it.list.length;i++){}}
	<li class="aui-list-item aui-list-item-middle" tapmode onclick="show('{{=it.list[i].id}}')">
		<div class="aui-list-item-inner aui-list-item-arrow" style="font-size: 0.9rem;">
			<b>{{=it.list[i].olderName}}</b>
			</li>
			{{}}}
</script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/doT.js"></script>
<script type="text/javascript" src="../../script/util.js"></script>
<script type="text/javascript" src="../../script/aui-pull-refresh.js"></script>
<script type="text/javascript">
	var pageNumber = 1;
	var searchText = '';
	apiready = function() {
		api.parseTapmode();
		loadData(pageNumber, searchText);
	};
	var pullRefresh = new auiPullToRefresh({
		container: document.querySelector('.aui-refresh-content'),
		triggerDistance: 100
	}, function(ret) {
		if (ret.status == "success") {
			loadData(++pageNumber, searchText);
		}
	});
	var searchBar = document.querySelector(".aui-searchbar-input");
	if (searchBar) {
		searchBar.onclick = function() {
			document.querySelector(".aui-searchbar-btn").style.marginRight = 0;
		}
	}
	document.querySelector(".aui-searchbar-btn").onclick = function() {
		this.style.marginRight = "-" + this.offsetWidth + "px";
		document.getElementById("search-input").value = '';
		document.getElementById("search-input").blur();
		$api.html($api.byId('list'), '');
		pageNumber = 1;
		loadData(pageNumber, searchText);
	}

	function doSearch() {
		var searchValue = document.getElementById("search-input").value;
		if (searchValue) {
			$api.html($api.byId('list'), '');
			loadData(1, searchValue);
			pageNumber = 0;
		}
	}

	function loadData(pageNumber, searchText) {
		pContainer1.style.marginTop = $api.byId('ast').clientHeight + 'px';
		api.showProgress({});
		api.ajax({
			url: base + 'gero/api/nurseTerminal/allLivingOlderList/pagingQuery',
			method: 'post',
			data: {
				values: {
					pageNo: pageNumber,
					pageSize: '40',
					token: $api.getStorage('userinfo').token,
					olderName: searchText
				}
			}
		}, function(ret, err) {
			console.log('ret' + JSON.stringify(ret));

			if (ret && ret.code == "200") {
				var template = $api.byId('listTemplate');
				var list_content = $api.byId('list');
				var pagefn = doT.template(template.text);
				list_content.insertAdjacentHTML('afterbegin', pagefn(ret));
				pullRefresh.cancelLoading();
			} else {
				doLogin();
			}
			api.hideProgress();
		});
	}

	// 查看详情
	function show(id) {
		openBrowse(api.wgtRootDir + '/html/person/show.html', '老人详情', false, 'person_show', id);
	}
</script>

</html>
